﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Threading;
using System.Reflection;

namespace Ecosystème
{
    public partial class ParametrePartie : Form
    {
        String cheminXML = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ParametrePartie)).CodeBase) + "/listeEtreVivant.xml";



        public ParametrePartie()
        {
            InitializeComponent();
            chargerTableau();
            //Arborescence arbre = new Arborescence(cheminXML); 
        }

        private void chargerTableau()
        {
            //tableau animaux
            dgvAnimaux.Rows.Add("Chameau");
            dgvAnimaux.Rows.Add("Chat");
            dgvAnimaux.Rows.Add("Chevre");
            dgvAnimaux.Rows.Add("Chien");
            dgvAnimaux.Rows.Add("Loup");
            dgvAnimaux.Rows.Add("Pigeon");

            //tableau végétaux
            dgvPlante.Rows.Add("Cactus");
            dgvPlante.Rows.Add("Tulipe");
        }

        /*private void majTableau()
        {
            int nbLigne = dgvAnimaux.RowCount;
            int i = 0;

            while (i != nbLigne)
            {
                if (dgvAnimaux.Rows[i].Cells["present"].Selected)
                {
                    dgvAnimaux.Rows[i].Cells["nbr"].ReadOnly = false;
                }
            i++;
            }

        }*/

        private void btnStart_Click(object sender, EventArgs e)
        {
            if (cbTailleCarte.Text != string.Empty)
            {
                this.Hide();
                Traitements.taille = new int[2];
                char separator = '*';
                string[] replacement = this.cbTailleCarte.Text.Split(separator);
                Traitements.taille[0] = Convert.ToInt32(replacement[0]);
                Traitements.taille[1] = Convert.ToInt32(replacement[0]);
                Traitements.dgvV = dgvPlante;
                Traitements.dgvA = dgvAnimaux;

                Thread theThread = new Thread(creerTheadGame);
                theThread.Start();
            }
            else
            {
                MessageBox.Show("Veuillez saisir la taille de la carte.");
            }

        }

        public void creerTheadGame()
        {

            Game1 game;
            game = new Game1();
            game.Run();

        }

        private void btnRetour_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAjoutEspece_Click(object sender, EventArgs e)
        {
            AjoutEspece f = new AjoutEspece();
            f.ShowDialog();
        }

        private void btnEditeurCarte_Click(object sender, EventArgs e)
        {

        }

    }
}
